import { SERVICE_PHONE_NUMBER } from "../../utils/constant";
import request from "../../utils/http";
import { anyObj, enter } from "../../utils/util"

// pages/serviceDetail/serviceDetail.ts
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		query: <anyObj>{},
		detail: <anyObj | null>null
	},

	/**
	 * 点击客服,拨打电话
	 */
	callService() {
		wx.makePhoneCall({phoneNumber: SERVICE_PHONE_NUMBER});
	},

	/**
	 * 点击下单
	 */
	async submit() {
		try {
			const orderId = await request({
				url: '/api/customers/reservation/save',
				method: 'POST',
				contentTypeForm: true,
				data: {
					serviceId: this.data.query.id,
					skuId: this.data.detail?.skuId
				},
				errToast: true,
				showLoading: {title: '正在下单...'}
			});
			enter({
				url: '../payOrderSuccess/payOrderSuccess',
				query: {
					orderId,
					serviceId: this.data.query.id,
				}
			});
		} catch (error) {
			
		}
	},

	async getDetail() {
		try {
			const detail = await request({
				url: '/api/customers/reservation/getOneServiceById',
				method: 'POST',
				query: {
					id: this.data.query.id
				},
				errToast: true,
				showLoading: {},
				contentTypeForm: true
			});
			this.setData({
				detail
			});
		} catch (error) {
			
		}
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(query: any) {
		this.setData({ query });
		if (query.id) {
			this.getDetail();
		}
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})